export default {
	data() {
		// 重复密码验证
		const pwdAgainCheck = async (rule, value, callback) => {
			//这样才能在回调里通过箭头函数获取到this对象
			if (value != this.temp.password) {
				callback(new Error('与密码不一致'))
			} else {
				//校验通过
				callback()
			}
		}
		return {
			rules: {
				account: [
					{ required: true, message: '请输入账号', trigger: 'blur' },
					{
						min: 2,
						max: 30,
						message: '请输入2~30个字符',
						trigger: 'blur',
					},
				],
				userName: [
					{ required: true, message: '请输入姓名', trigger: 'blur' },
					{
						min: 2,
						max: 8,
						message: '请输入2~8位汉字、字母或数字',
						trigger: 'blur',
					},
				],
				password: [{
						required: true,
						message: '请输入6~16个字符',
						trigger: 'blur',
						min: 6,
						max: 16,
					},
					{
						validator: function(rule, value, callback) {
							//校验中文的正则：/^[\u4e00-\u9fa5]{0,}$/
							if ((value + '').length < 6) {
								callback(new Error('请输入6~16个字符'))
							} else {
								//校验通过
								callback()
							}
						},
						trigger: 'blur',
					},
				],
				confirmPassword: [{
						required: true,
						message: '请输入确认密码',
						trigger: 'blur',
					},
					{
						validator: pwdAgainCheck,
						trigger: 'blur',
					},
				],
				phone: [{
						required: true,
						message: '请输入联系电话',
						trigger: 'blur',
					},
					{
						type: 'number',
						validator: function(rule, value, callback) {
							if (/^1[345789]\d{9}$/.test(value) == false) {
								callback(new Error('请输入11位手机号'))
							} else {
								//校验通过
								callback()
							}
						},
						message: '请输入11位有效手机号码',
						trigger: ['blur', 'change'],
					},
				],
				deptId: [{
					required: true,
					message: '请选择部门',
					trigger: ['blur', 'change'],
				}, ],
				roleIds: [{
					required: true,
					message: '请选择用户角色',
					trigger: ['blur', 'change'],
				}, ],
			},
		}
	},
}